//
//  SwiftAlias.swift
//  XXSync
//
//  Created by Rdxer on 2017/8/4.
//  Copyright © 2017年 Rdxer. All rights reserved.
//

import Foundation
import UIKit
import SVProgressHUD
import MBProgressHUD
import Moya
//import PageMenu


typealias CallBackClosure = (()->())?
typealias CallBackClosure_1BoolV = ((_ v:Bool)->())?
typealias CallBackClosure_1AnyV = ((_ v:Any)->())?
typealias CallBackClosure_1IntV = ((_ v:Int)->())?
typealias CallBackClosure_1StringV = ((_ v:String)->())?

//typealias HUD = APHHUD
typealias HUD = SVProgressHUD

func configHUD() {
    
    if HUD.classForCoder() == APHHUD.classForCoder() {
        APHHUD.setAPH_Loading(AppImage.loading_gif)
    }else{
        HUD.setDefaultStyle(.dark)
        HUD.setMinimumSize(.init(width: 100, height: 80))
        HUD.setMinimumDismissTimeInterval(1.5)
    }
}

func showErrorHUD(_ err:Error){

    var showMessage = "网络不给力,请检查网络后重试"
    
    switch err {
    case let MoyaError.underlying(_Error, _):
        if let _err = _Error as? NSError,let message = _err.userInfo["errMsg"] as? String{
            showMessage = message
            if let code = _err.userInfo["errCode"] as? Int,code == 1001{
                HUD.dismiss()
                return;
            }
        }
    case MoyaError.jsonMapping(_):
        showMessage = "服务器返回数据格式错误..请重试..."
    default:
        break;
    }
    HUD.showError(withStatus: showMessage)
}

func addTransparentHUDTo(_ view:UIView) -> MBProgressHUD {
    
    let hud_mb = MBProgressHUD.showAdded(to: view, animated: true)
    hud_mb.bezelView.style = .solidColor
    hud_mb.bezelView.backgroundColor = UIColor.clear
    hud_mb.mode = .customView
    
    hud_mb.customView = UIImageView.init(image: AppImage.loading_gif)
    
    return hud_mb
}

/// iPhoneX
func isiPhoneX() -> Bool {
    return CGSize.init(width: 375, height: 812).equalTo(UIScreen.main.bounds.size)
}

public class XXConstant: NSObject {
    
    /// 24 or 0
    static var safeAreaTop:CGFloat{
        return isiPhoneX() ? 24 : 0
    }
    
    /// 34 or 0
    static var safeAreaBottom:CGFloat{
        return isiPhoneX() ? 34 : 0
    }
    
    /// 44 or 20
    static var statusBarHeight:CGFloat {
        return isiPhoneX() ? 44 : 20
    }
    
    /// 34 + 49 or 49
    static var tabbarHeigh:CGFloat {
        return isiPhoneX() ? (34 + 49) : 49
    }
    
    /// statusBarHeight (44 or 20) + 44
    static var navigationBarHeigh:CGFloat {
        return statusBarHeight + 44
    }
    
}


// MARK: -
// MARK: - 屏幕
extension XXConstant{
    /// UIScreen.main.bounds.width
    static var W:CGFloat {
        return UIScreen.main.bounds.width
    }
    /// UIScreen.main.bounds.height
    static var H:CGFloat {
        return UIScreen.main.bounds.height
    }
}



// MARK: -
// MARK: - 通知
extension Notification.Name{
    static let AddConsultSelected_didDelete = Notification.Name.init("nc_AddConsultSelected_didDelete")
    
    /// 审定列表页需要刷新
    static let WorkTableView_needRefresh = Notification.Name.init("WorkTableView_needRefresh")
    
    /// 审定页 审定表 需要刷新 --
    static let WorkView_table_needRefresh = Notification.Name.init("WorkView_table_needRefresh")
    
    /// 请假页面 需要刷新 --
    static let Vacation_table_needRefresh = Notification.Name.init("Vacation_table_needRefresh")
}


//let PageMenuOption_Parameters: [CAPSPageMenuOption] = [
//    .useMenuLikeSegmentedControl(true),
//    CAPSPageMenuOption.selectedMenuItemLabelColor(AppColor.mainColor),
//    CAPSPageMenuOption.unselectedMenuItemLabelColor(AppColor.textColor),
//    CAPSPageMenuOption.scrollMenuBackgroundColor(UIColor.white),
//    CAPSPageMenuOption.selectionIndicatorColor(AppColor.mainColor),
//
//    CAPSPageMenuOption.menuItemSeparatorColor(UIColor.clear),
//    CAPSPageMenuOption.addBottomMenuHairline(true),
//    CAPSPageMenuOption.bottomMenuHairlineColor(AC.grayDividerColor),
////    CAPSPageMenuOption.menuMargin(0),
//    CAPSPageMenuOption.menuItemMargin(0),
//    //// ---
//    CAPSPageMenuOption.selectionIndicatorWidthScale(0.33333),
//    CAPSPageMenuOption.menuMargin(0),
//    CAPSPageMenuOption.menuHeight(50),
//]




